package com.jxc.servlet.pattern;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/pattern/*")
public class PatternServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取当前访问的url,由于req.getRequestURL()是StringBuffer类型的，所以用toString转换成String类型
        String url = req.getRequestURL().toString();
        // 获取id，从网址的最后一个 / 开始，获取 / 后面的内容，+1是因为从0开始的
        String id = url.substring(url.lastIndexOf("/")+1);
        resp.getWriter().print("<h1>"+id+"</h1>");
    }
}
